package com.acme.bankapp.util;

import com.acme.bankapp.domain.bank.Email;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by Student on 21.11.2014.
 */
public class EmailQueue {
    private final List<Email> queue = new LinkedList<>();

    public void enqueue(Email email) {
        synchronized (queue) {
            queue.add(email);
            queue.notify();
        }
    }

    public Email dequeue() throws InterruptedException {
        synchronized (queue) {
            while (queue.isEmpty()) {
                queue.wait();
            }
            return queue.remove(0);
        }
    }

    public boolean isEmpty() {
        synchronized (queue) {
            return queue.isEmpty();
        }
    }
}
